/*
 * Package : view.main 
 * Class : JPanelManagerBookAndCD.java
 * Create Date : 04-12-2008
 * Purpose : 
 */
package view;

import java.awt.Color;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import java.util.Vector;

import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.JTable;
import javax.swing.border.TitledBorder;
import javax.swing.table.DefaultTableModel;


/**
 * @author Mai Thu 04-12-2008 : 21:08:57
 */
public class JPanelManagerBookAndCD extends JPanel {
	private javax.swing.JButton jButton_Add;
	private javax.swing.JButton jButton_Edit;
	private javax.swing.JButton jButton_Delete;
	private javax.swing.JLabel jLabel1;
	private javax.swing.JLabel jLabel2;
	private javax.swing.JScrollPane jScrollPane1;
	private javax.swing.JSeparator jSeparator1;
//	private ReportData reportData;
//	private SeviceData seviceData;

	private JTable table;
	private DefaultTableModel defaultTableModel;

	private Vector<String> rowHeader = new Vector<String>();
	private Vector<String> rowData = new Vector<String>();

	/**
	 * 
	 */
	public JPanelManagerBookAndCD() {
		// TODO Auto-generated constructor stub
		GridBagConstraints gridBagConstraints;
		jLabel1 = new javax.swing.JLabel("Quáº£n lÃ½ tÃ i nguyÃªn sÃ¡ch/CD");
//		jLabel1.setFont(new Font(FontUtil.MONOSPACED, Font.BOLD,
//				FontUtil.SIZE_28));
		jButton_Add = new javax.swing.JButton("ThÃªm má»›i sÃ¡ch/CD");
		jButton_Edit = new javax.swing.JButton("Chá»‰nh sá»­a thÃ´ng tin sÃ¡ch/CD");
		jButton_Delete = new javax.swing.JButton("XoÃ¡ thÃ´ng tin cá»§a sÃ¡ch/CD");
		jSeparator1 = new javax.swing.JSeparator();
		jLabel2 = new javax.swing.JLabel(
				"Danh sÃ¡ch táº¥t cáº£ cÃ¡c sÃ¡ch cÃ³ trong tÃ i nguyÃªn : ");
//		jLabel2.setFont(new Font(FontUtil.MONOSPACED, Font.BOLD,
//				FontUtil.SIZE_18));
		jScrollPane1 = new javax.swing.JScrollPane();
		jSeparator1.setOrientation(JSeparator.VERTICAL);

		// do du lieu vao bang
////		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
//		session.beginTransaction();
//		reportData = ReportData.SIGNLETON;
//		List<Item> items = reportData.getAllItem();
		rowHeader.add("TÃªn");
		rowHeader.add("Loáº¡i");
		rowHeader.add("GiÃ¡");
		rowHeader.add("NgÃ y mua");
		rowHeader.add("NÆ¡i mua");
		rowHeader.add("Sá»‘ láº§n mÆ°á»£n");
		// rowHeader.add("Ghi chÃº");
		table = new JTable();
		defaultTableModel = new DefaultTableModel(rowHeader, 0);
		table.setModel(defaultTableModel);
		// auto sort table
		table.setAutoCreateRowSorter(true);
//		System.out.println(items.size());
//		if (items.size() != 0) {
//			for (Item item : items) {
//				rowData = new Vector<String>();
//				rowData.add(item.getName());
//				rowData.add(item.getType() + "");
//				rowData.add(item.getPrice() + "");
//				rowData.add(UtilDate.dateToString(item.getBuyDate().getTime()));
//				rowData.add(item.getBuyPlace());
//				rowData.add(item.getNumberBorrowed() + "");
//				// rowData.add(item.getNote().toString());
//
//				defaultTableModel.addRow(rowData);
//			}
//		}
//		session.getTransaction().commit();
		jScrollPane1.setViewportView(table);

//		// su kien button
//		jButton_Add.addActionListener(new ActionListener() {
//
//			@Override
//			public void actionPerformed(ActionEvent e) {
//				new JFrameAddItem(JPanelManagerBookAndCD.this);
//
//			}
//
//		});
//		jButton_Delete.addActionListener(new ActionListener() {
//
//			@Override
//			public void actionPerformed(ActionEvent e) {
//				int selected = table.getSelectedRow();
//				if (selected < 0) {
//					JOptionPane.showMessageDialog(JPanelManagerBookAndCD.this,
//							"HÃ£y chá»�n sach/CD Ä‘á»ƒ xoÃ¡", "ThÃ´ng bÃ¡o",
//							JOptionPane.ERROR_MESSAGE);
//				} else {
//					String name = (String) defaultTableModel.getValueAt(
//							selected, 0);
//					defaultTableModel.removeRow(selected);
//					seviceData =  SeviceData.SIGNLETON;
//					HibernateUtil.getSessionFactory().getCurrentSession()
//							.beginTransaction();
//					Item item = reportData.getItemByName(name.trim());
//					seviceData.delete(item);
//					HibernateUtil.getSessionFactory().getCurrentSession()
//							.getTransaction().commit();
//				}
//
//			}
//
//		});
//		jButton_Edit.addActionListener(new ActionListener() {
//
//			@Override
//			public void actionPerformed(ActionEvent e) {
//				int selected = table.getSelectedRow();
//				if (selected < 0) {
//					JOptionPane.showMessageDialog(JPanelManagerBookAndCD.this,
//							"HÃ£y chá»�n sach/CD Ä‘á»ƒ chá»‰nh sá»­a", "ThÃ´ng bÃ¡o",
//							JOptionPane.ERROR_MESSAGE);
//				} else {
//					String name = (String) defaultTableModel.getValueAt(
//							selected, 0);
//					new JFrameEditItem(name.trim());
//				}
//
//			}
//
//		});

		// set layout
		this.setLayout(new java.awt.GridBagLayout());

		gridBagConstraints = new GridBagConstraints();
		gridBagConstraints.gridx = 0;
		gridBagConstraints.gridy = 0;
		gridBagConstraints.gridwidth = 3;
		gridBagConstraints.fill = GridBagConstraints.VERTICAL;
		gridBagConstraints.anchor = GridBagConstraints.SOUTH;
		this.add(jLabel1, gridBagConstraints);

		gridBagConstraints = new GridBagConstraints();
		gridBagConstraints.gridx = 0;
		gridBagConstraints.gridy = 1;
		gridBagConstraints.anchor = GridBagConstraints.WEST;
		gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
		this.add(jButton_Add, gridBagConstraints);

		gridBagConstraints = new GridBagConstraints();
		gridBagConstraints.gridx = 0;
		gridBagConstraints.gridy = 2;
		gridBagConstraints.anchor = GridBagConstraints.WEST;
		gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
		this.add(jButton_Edit, gridBagConstraints);

		gridBagConstraints = new GridBagConstraints();
		gridBagConstraints.gridx = 0;
		gridBagConstraints.gridy = 3;
		gridBagConstraints.anchor = GridBagConstraints.WEST;
		gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
		this.add(jButton_Delete, gridBagConstraints);

		gridBagConstraints = new GridBagConstraints();
		gridBagConstraints.gridx = 1;
		gridBagConstraints.gridy = 2;
		gridBagConstraints.gridheight = 6;
		gridBagConstraints.ipady = 300;
		gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
		this.add(jSeparator1, gridBagConstraints);

		gridBagConstraints = new GridBagConstraints();
		gridBagConstraints.gridx = 2;
		gridBagConstraints.gridy = 2;
		gridBagConstraints.anchor = GridBagConstraints.WEST;
		gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
		this.add(jLabel2, gridBagConstraints);

		gridBagConstraints = new GridBagConstraints();
		gridBagConstraints.gridx = 2;
		gridBagConstraints.gridy = 3;
		gridBagConstraints.gridheight = 8;
		gridBagConstraints.fill = GridBagConstraints.BOTH;
		gridBagConstraints.ipadx = 400;
		gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
		this.add(jScrollPane1, gridBagConstraints);

		gridBagConstraints = new GridBagConstraints();
		gridBagConstraints.gridx = 2;
		gridBagConstraints.gridy = 12;
		gridBagConstraints.gridheight = 3;
		gridBagConstraints.fill = GridBagConstraints.BOTH;
		gridBagConstraints.ipadx = 400;
		gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
		this.add(new JLabel("    "), gridBagConstraints);

	}

	/**
	 * @param item
	 */
//	public void addRowItem(Item item) {
//		rowData = new Vector<String>();
//		rowData.add(item.getName());
//		rowData.add(item.getType() + "");
//		rowData.add(item.getPrice() + "");
//		rowData.add(UtilDate.dateToString(item.getBuyDate().getTime()));
//		rowData.add(item.getBuyPlace());
//		rowData.add(item.getNumberBorrowed() + "");
//		defaultTableModel.addRow(rowData);
//	}

}
